< previous page page_166 next page >

Page 166
If Sales_Amt > 500 Then Sales_Amt = Sales_Amt * .90
Whenever you must execute more than one line of code, you should use the If-Then-End If block. Now, did you know that you can execute several lines of code on a single line? This is actually a hold-over from the old DOS Basic days. For example, the following code:
If (keyascii < 48 Or keyascii > 58) And keyascii <> 8 Then
    Beep
    keyascii = 0
End If
could have been written as follows:
If (keyascii < 48 Or keyascii > 58) And keyascii <> 8 Then Beep : keyascii = 0
By separating each statement with a colon (:), you can execute several lines of code without using the End If block. Most programmers have never used the If statement differently than the way it has been shown here. However, the statements that can be executed when a condition is true are not limited to standard lines of code. If you must test a condition and then loop through an array to process the information, you could call a subroutine that loops through the array, or you could code the following:
If Update_Records Then
    Do Until (EOF(1))
        processing code
    Loop
Else
    MsgBox No records have been updated.
End If
So, when needed, you can mix any type of Visual Basic statement with the If-Then statement block. The last version of the If-Then statement enables you to set sections of code to be used only when certain conditions occur. The #If-Then-#Else directives will instruct the Visual Basic compiler to conditionally compile different sections of code. The following code will produce different executable files depending on the operating system on which it was compiled:
#If Mac Then
. Place exclusively Mac statements here.
 Otherwise, if it is a 32-bit Windows program, do this:
#Elself Win32 Then
. Place exclusively 32-bit Windows statements here.
 Otherwise, if it is neither, do this:
#Else
. Place other platform statements here.
#End If
Try this code in your application. If your computer is running Windows 95 or Windows

 
< previous page page_166 next page >

If you like this book, buy it!